package com.xpec.c4.db.filter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * 检查AccountManager的类，移除AccountManager类里IShareMap中长时间未登录的账户,
 * 同时移除CashManager里对应的数据
 * 
 * @author zhongzhengkai
 * 
 */
public class AccountIdleRemover implements Runnable {

	@SuppressWarnings("unused")
	private Log log = LogFactory.getLog(AccountIdleRemover.class);

	/**
	 * 限定的闲置时间
	 */
	@SuppressWarnings("unused")
	private static long idleTime = FilterConstants.ACCOUNT_IDLE_TIME;

	// private static long idleTime = ServerProperties.getInt("idleTime", 43200)
	// * TimeConstants.MILLI_SECOND_PRE_SECOND;

	public AccountIdleRemover() {

	}

	@Override
	public void run() {

		
		/**		  
		 FIXME 這邊的清除動作已經無效
		 
		CashManager cashManager = CashManager.getInstance();
		List<Account> accs = AccountManager.getInstance().getListOfAccounts();
		List<String> accsForLog = new ArrayList<String>();

		for (Account account : accs) {
			
			if (account == null) {
				continue;
			}
			
			if(account.isOnline()){
				continue;
			}
			
			long t = System.currentTimeMillis();
			if (t - account.getLoadTime() > idleTime) {
				String accountId = account.getAccountId();
				accsForLog.add(accountId);
				AccountManager.getInstance().removeAccount(accountId);
				cashManager.removeCashData(accountId);
			}
		}
		
		for (int i = 0; i < accsForLog.size(); i++) {
			log.info("the Account " + accsForLog.get(i)
					+ " and its cashDaTa has been removed successfully!");
		}
		log.info("Caculation:"+accsForLog.size()+" Accounts had been romove successfully! ");
		accsForLog.clear();
		
		*/
	}

}
